package org.openwebtop.sunshine.action.history;

import org.apache.commons.lang.StringUtils;
import org.openwebtop.sunshine.dao.CodeRepositoryDAO;
import org.openwebtop.sunshine.domain.CodeRepository;
import org.openwebtop.sunshine.subversion.SubversionClient;
import org.openwebtop.sunshine.subversion.SubversionClientFactory;
import org.openwebtop.sunshine.subversion.model.RevisionInfo;

import com.opensymphony.xwork.ActionSupport;

public class ChangesetAction {
	private SubversionClientFactory subversionClientFactory;
	private CodeRepositoryDAO codeRepositoryDAO;

	// Getter
	private CodeRepository codeRepository;
	private RevisionInfo revisionInfo;

	// Params
	private String name;
	private long revision;

	public String execute() throws Exception {
		if (StringUtils.isNotBlank(name)) {
			codeRepository = codeRepositoryDAO.getCodeRepository(name);

			if (codeRepository != null) {
				final SubversionClient subversionClient = subversionClientFactory.getSubversionClient(codeRepository);
				revisionInfo = subversionClient.getRevisionInfo(revision);
			}
		}

		return ActionSupport.SUCCESS;
	}

	public void setSubversionClientFactory(SubversionClientFactory subversionClientFactory) {
		this.subversionClientFactory = subversionClientFactory;
	}

	public void setCodeRepositoryDAO(CodeRepositoryDAO codeRepositoryDAO) {
		this.codeRepositoryDAO = codeRepositoryDAO;
	}

	public CodeRepository getCodeRepository() {
		return codeRepository;
	}

	public RevisionInfo getRevisionInfo() {
		return revisionInfo;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setRevision(long revision) {
		this.revision = revision;
	}

}
